$(function () {
    //全局定义页数与总条数
    var markid = getUrlString('markid');
    // var markid = '3b70887e5d841ff8ab7388ea5f41a5af';
    var page = -1,totalSize = 0,sort= 0;


    var mRefresh = new MiniRefresh({
        container: '#mrefresh', //这里是插件的容器ID
        down: {
            isAuto: false,
            callback: function () {
                // 下拉后的回调事件 ，你可以在这里执行你的后台请求数据函数，达到刷新数据的作用
                $('#listData').empty();
                totalSize = 0;
                page = -1;
                mRefresh.endDownLoading();
            }
        }
        ,
        up: {
            isAuto: true,
            callback: function () {
                // 向上拉后的回调事件
                page += 1;
                getDate(page)
            }
        }
    });

    /*联网加载列表数据*/
    function getDate(page) {
        //延时一秒,模拟联网
        var params = {
            'markid':markid,
            'page': page,
        };
        getData('get', '/niu/apiv3/niu_backboardlist.php', params, function (data) {
            console.log(data);
            if(data.resultcode === '0' ){
                var append = '';
                $(data.data).each(function () {
                    var chenghaoStr = (this.userlv).substring(3);
                    if(this.niutoylevel > 2 || this.grand_type !== '10'){
                        append += '<li  onclick="window.location.href = \'dancool://member=\'+'+this.userid+';" class="liActive">' ;
                    }else {
                        append += '<li onclick="window.location.href = \'dancool://member=\'+'+this.userid+';">' ;
                    }

                    if (this.grand_type === '0') {
                        append += '  <img class="lastWFitst" src="../../res/img/eggTV/last.png" alt="">  ';
                    }else if(this.grand_type === '1'){
                        append += '  <img class="lastWFitst" src="../../res/img/eggTV/W.png" alt="">  ';
                    }else if(this.grand_type === '2'){
                        append += '  <img class="lastWFitst" src="../../res/img/eggTV/first.png" alt="">  ';
                    }else if(this.grand_type === '3'){
                        append += '  <img class="lastWFitst" src="../../res/img/eggTV/M.png" alt="">  ';
                    }
                    append+= '           <input type="hidden" class="id" value="'+this.userid+'"> '+
                        '           <div class="user">' +
                        '               <div class="userPic">' +
                        '                   <img src="'+this.userfaceurl+'" alt="">' +
                        '               </div>' +
                        '               <div class="userName">' +
                        '                   <p>' ;
                    if(this.chenghao !== ''){
                        append += '         <span class="spanACtive">'+this.usernick+'</span>' ;
                    }else {
                        append += '         <span class="spanACtive2">'+this.usernick+'</span>' ;
                    }

                    if(this.uservip === '1'){
                        append +=  '               <img style="width: 1rem" src="../../res/img/eggTV/monthCard@2x.png" alt="">' ;
                    }
                    if (chenghaoStr < 6 && chenghaoStr > 0){
                        append += '<img src="../../res/img/common/bronzeIcon.png" alt="">' ;
                    }else if (5 < chenghaoStr && chenghaoStr < 11){
                        append += '<img src="../../res/img/common/silverIcon.png" alt="">' ;
                     }else if (10 < chenghaoStr && chenghaoStr < 16){
                        append += '<img src="../../res/img/common/goldIcon.png" alt="">' ;
                    }else if (15 < chenghaoStr && chenghaoStr < 21){
                        append += '<img src="../../res/img/common/platinaIcon.png" alt="">' ;
                    }else if(20 < chenghaoStr && chenghaoStr < 26){
                        append += '<img src="../../res/img/common/diamondIcon.png" alt="">' ;
                    }
                   if(this.chenghao !== ''){
                       append += '<img style="height: 1rem;width: initial" src="https://api.odancool.com'+this.huiyuaninfo2+'" alt="">                  </p>' ;
                   }
                    append+=     '                   <p>'+subTime(this.time)+'</p>' +
                        '               </div>' +
                        '           </div>' +
                        '           <div class="brief">' +
                        '               <p>抽到了 '+this.toysname+'</p>' +
                        '               <p>' +
                        '                   <img src="'+this.toyspic+'" alt="">' +
                        '               </p>' +
                        '           </div>' +
                        '       </li>'
                });
                $('#listData').append(append);


                totalSize = totalSize + 10;
                if (totalSize > data.datacount)
                    mRefresh.endUpLoading(true);
                else{
                    mRefresh.endUpLoading(false);
                }
                // $('#listData li').click(function () {
                //     var id = $(this).find('.id').val();
                //     window.location.href = 'dancool://member='+id;
                // });

            }else {
                laymsg(data.msg)
            }

        });
    }

});
